#include "react-native-awesome-module.h"

namespace example
{
  int multiply(float a, float b)
  {
    return a * b;
  }
}
/*

// feather-filter.cpp : 羽化
// @mango
// https://mangoroom.cn

#include <iostream>
#include<cmath>
#include<opencv2/opencv.hpp>



int main()
{
    //1、通过对rgb值增加额外的V值实现朦胧效果
    //2、通过控制V值的大小实现范围控制。
    //3、V = 255 * 当前点Point距中点距离的平方s1 / (顶点距中点的距离平方s2 * mSize);
    //4、s1 有根据 ratio 修正 dx dy值。

    cv::Mat img = cv::imread("fruit.jpg");

    if (img.empty())
    {
        std::cout << "Failed to read the image!" << std::endl;
        return -1;
    }

    // s2
    int center_x = img.cols >> 1;
    int center_y = img.rows >> 1;
    int s2 = center_x * center_x + center_y * center_y;

    // 宽长比例 ratio
    double ratio = img.cols > img.rows ? static_cast<double>(img.rows) / img.cols : static_cast<double>(img.cols) / img.rows;

    // mSize
    // 2、通过控制V值的大小实现范围控制。
    double mSize = 0.5;

    for (size_t i = 0; i < img.rows; i++)
    {
        for (size_t j = 0; j < img.cols; j++)
        {
            double dx = static_cast<double>(std::abs(center_x - static_cast<int>(j)));
            double dy = static_cast<double>(std::abs(center_y - static_cast<int>(i)));


            //4、s1 有根据 ratio 修正 dx dy值。
            if (center_x > center_y)
            {
                dx = dx * ratio;
            }
            else
            {
                dy = dx * ratio;
            }

            // s1
            double s1 = dx * dx + dy * dy;
            // v
            // 3、V = 255 * 当前点Point距中点距离的平方s1 / (顶点距中点的距离平方s2 * mSize);
            double v = 255 * s1 / (s2 * mSize);

            int b = img.at<cv::Vec3b>(i, j)[0];
            int g = img.at<cv::Vec3b>(i, j)[1];
            int r = img.at<cv::Vec3b>(i, j)[2];

            // 1、通过对rgb值增加额外的V值实现朦胧效果
            img.at<cv::Vec3b>(i, j)[0] = cv::saturate_cast<uchar>(b + v);
            img.at<cv::Vec3b>(i, j)[1] = cv::saturate_cast<uchar>(g + v);
            img.at<cv::Vec3b>(i, j)[2] = cv::saturate_cast<uchar>(r + v);
        }
    }

    cv::imshow("羽化特效", img);
    cv::waitKey(0);

    return 0;
}
*/

/*

// black and white filter
//@mango

#include<iostream>
#include<opencv2/opencv.hpp>

int main()
{
    // 以灰度图的方式读取图像
    cv::Mat img = cv::imread("fruit.jpg", 0);

    for (size_t i = 0; i < img.rows; i++)
    {
        for (size_t j = 0; j < img.cols; j++)
        {
            if (img.at<uchar>(i, j) > 128)
            {
                img.at<uchar>(i, j) = 255;
            }
            else
            {
                img.at<uchar>(i, j) = 0;
            }
        }
    }

    cv::imshow("黑白滤镜", img);
    cv::waitKey(0);
    return 0;
}
*/

/*
// comic-filter.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// @mango

#include<iostream>
#include<cmath>
#include<opencv2/opencv.hpp>



int main()
{

    cv::Mat img = cv::imread("fruit.jpg");

    for (size_t i = 0; i < img.rows; i++)
    {
        for (size_t j = 0; j < img.cols; j++)
        {
            int r = img.at<cv::Vec3b>(i, j)[2];
            int g = img.at<cv::Vec3b>(i, j)[1];
            int b = img.at<cv::Vec3b>(i, j)[0];

            double R = std::abs(g - b + g + r) * r / 256;
            double G = std::abs(b - g + b + r) * r / 256;
            double B = std::abs(b - g + b + r) * g / 256;

            img.at<cv::Vec3b>(i, j)[0] = cv::saturate_cast<uchar>(B);
            img.at<cv::Vec3b>(i, j)[1] = cv::saturate_cast<uchar>(G);
            img.at<cv::Vec3b>(i, j)[2] = cv::saturate_cast<uchar>(R);
        }
    }
    cv::imshow("连环画滤镜", img);

    cv::waitKey(0);
    return 0;
}
*/

/*

// drawing-filter.cpp : 素描滤镜
// @mango

#include <iostream>
#include <opencv2/opencv.hpp>
#include<cmath>

int main()
{
    cv::Mat img = cv::imread("fruit.jpg");
    if (img.empty())
    {
        std::cout << "Failed to read the image!" << std::endl;
        return -1;
    }

    //1、去色
    cv::Mat gray(img.size(), CV_8UC3);
    for (size_t i = 0; i < img.rows; i++)
    {
        for (size_t j = 0; j < img.cols; j++)
        {
            int max = std::max(
                std::max(img.at<cv::Vec3b>(i, j)[0], img.at<cv::Vec3b>(i, j)[1]),
                img.at<cv::Vec3b>(i, j)[2]
            );

            int min = std::min(
                std::min(img.at<cv::Vec3b>(i, j)[0], img.at<cv::Vec3b>(i, j)[1]),
                img.at<cv::Vec3b>(i, j)[2]
            );

            for (size_t k = 0; k < 3; k++)
            {
                gray.at<cv::Vec3b>(i, j)[k] = (max + min) / 2;
            }
        }
    }

    //2、复制去色图层，并且反色
    cv::Mat gray_revesal(img.size(), CV_8UC3);
    for (size_t i = 0; i < gray.rows; i++)
    {
        for (size_t j = 0; j < gray.cols; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                gray_revesal.at<cv::Vec3b>(i, j)[k] = 255 - gray.at<cv::Vec3b>(i, j)[k];
            }
        }
    }

    //3、对反色图像进行高斯模糊；
    cv::GaussianBlur(gray_revesal, gray_revesal, cv::Size(7, 7), 0);

    //4、模糊后的图像叠加模式选择颜色减淡效果。
    // 减淡公式：C =MIN( A +（A×B）/（255-B）,255)，其中C为混合结果，A为去色后的像素点，B为高斯模糊后的像素点。
    cv::Mat result(gray.size(), CV_8UC3);
    for (size_t i = 0; i < gray.rows; i++)
    {
        for (size_t j = 0; j < gray.cols; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                int a = gray.at<cv::Vec3b>(i, j)[k];
                int b = gray_revesal.at<cv::Vec3b>(i, j)[k];
                int c = std::min(a + (a * b) / (255 - b), 255);

                result.at<cv::Vec3b>(i, j)[k] = c;
            }

        }
    }

    cv::imshow("素描效果", result);
    cv::waitKey(0);

    return 0;
}*/

/*

// vintage-filter.cpp : 怀旧滤镜
// @mango

#include <iostream>
#include<opencv2/opencv.hpp>



int main()
{

    cv::Mat img = cv::imread("fruit.jpg");

    for (size_t i = 0; i < img.rows; i++)
    {
        for (size_t j = 0; j < img.cols; j++)
        {

            img.at<cv::Vec3b>(i, j)[1] = cv::saturate_cast<uchar>(0.349*img.at<cv::Vec3b>(i, j)[2] + 0.686*img.at<cv::Vec3b>(i, j)[1] + 0.168*img.at<cv::Vec3b>(i, j)[0]);// green
            img.at<cv::Vec3b>(i, j)[2] = cv::saturate_cast<uchar>(0.393*img.at<cv::Vec3b>(i, j)[2] + 0.769*img.at<cv::Vec3b>(i, j)[1] + 0.189*img.at<cv::Vec3b>(i, j)[0]);// red
                        img.at<cv::Vec3b>(i, j)[0] = cv::saturate_cast<uchar>(0.272*img.at<cv::Vec3b>(i, j)[2] + 0.534*img.at<cv::Vec3b>(i, j)[1] + 0.131*img.at<cv::Vec3b>(i, j)[0]);// blue
        }
    }
    cv::imshow("怀旧滤镜", img);

    cv::waitKey(0);
    return 0;
}
*/
